<template>
    <el-dialog
            :title="!dataForm.orderId ? '新增' : '修改'"
            :close-on-click-modal="false"
            :visible.sync="visible">
        <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="120px">
                            <el-form-item label="主键ID" prop="id">
                        <el-input v-model.number="dataForm.id" placeholder="主键ID"></el-input>
                </el-form-item>
                <el-form-item label="预测生成的时间" prop="predictionTime">
                        <el-date-picker
                                v-model="dataForm.predictionTime"
                                type="datetime"
                                placeholder="预测生成的时间">
                        </el-date-picker>
                </el-form-item>
                <el-form-item label="预测周期（短期、中长期）" prop="predictionPeriod">
                        <el-input v-model="dataForm.predictionPeriod" placeholder="预测周期（短期、中长期）"></el-input>
                </el-form-item>
                <el-form-item label="预测的发电功率" prop="predictedPower">
                        <el-input v-model="dataForm.predictedPower" placeholder="预测的发电功率"></el-input>
                </el-form-item>
                <el-form-item label="实际发电功率（用于评估）" prop="actualPower">
                        <el-input v-model="dataForm.actualPower" placeholder="实际发电功率（用于评估）"></el-input>
                </el-form-item>
                <el-form-item label="预测误差指标（如相对误差、均方根误差等）" prop="errorMetric">
                        <el-input v-model="dataForm.errorMetric" placeholder="预测误差指标（如相对误差、均方根误差等）"></el-input>
                </el-form-item>
                <el-form-item label="不确定性量化指标（如置信区间、概率分布等）" prop="uncertaintyMetric">
                        <el-input v-model="dataForm.uncertaintyMetric" placeholder="不确定性量化指标（如置信区间、概率分布等）"></el-input>
                </el-form-item>
                <el-form-item label="预测结果可视化类型" prop="visualizationType">
                        <el-input v-model="dataForm.visualizationType" placeholder="预测结果可视化类型"></el-input>
                </el-form-item>
                <el-form-item label="预测结果的目标用户群体（如电网调度中心、发电企业运维人员等）" prop="userGroup">
                        <el-input v-model="dataForm.userGroup" placeholder="预测结果的目标用户群体（如电网调度中心、发电企业运维人员等）"></el-input>
                </el-form-item>
                <el-form-item label="记录创建时间" prop="createdAt">
                        <el-date-picker
                                v-model="dataForm.createdAt"
                                type="datetime"
                                placeholder="记录创建时间">
                        </el-date-picker>
                </el-form-item>
                <el-form-item label="记录更新时间" prop="updatedAt">
                        <el-date-picker
                                v-model="dataForm.updatedAt"
                                type="datetime"
                                placeholder="记录更新时间">
                        </el-date-picker>
                </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
    </el-dialog>
</template>

<script>
    export default {
        data () {
            return {
                visible: false,
                dataForm: {
                    id: null,
                    predictionTime: null,
                    predictionPeriod: null,
                    predictedPower: null,
                    actualPower: null,
                    errorMetric: null,
                    uncertaintyMetric: null,
                    visualizationType: null,
                    userGroup: null,
                    createdAt: null,
                    updatedAt: null,
                },
                dataRule: {
                    id: [
                        { required: true, message: '主键ID不能为空', trigger: 'blur' }
                    ],
                    predictionTime: [
                        { required: true, message: '预测生成的时间不能为空', trigger: 'blur' }
                    ],
                    predictionPeriod: [
                        { required: true, message: '预测周期（短期、中长期）不能为空', trigger: 'blur' }
                    ],
                    predictedPower: [
                        { required: true, message: '预测的发电功率不能为空', trigger: 'blur' }
                    ],
                    actualPower: [
                        { required: true, message: '实际发电功率（用于评估）不能为空', trigger: 'blur' }
                    ],
                    errorMetric: [
                        { required: true, message: '预测误差指标（如相对误差、均方根误差等）不能为空', trigger: 'blur' }
                    ],
                    uncertaintyMetric: [
                        { required: true, message: '不确定性量化指标（如置信区间、概率分布等）不能为空', trigger: 'blur' }
                    ],
                    visualizationType: [
                        { required: true, message: '预测结果可视化类型不能为空', trigger: 'blur' }
                    ],
                    userGroup: [
                        { required: true, message: '预测结果的目标用户群体（如电网调度中心、发电企业运维人员等）不能为空', trigger: 'blur' }
                    ],
                    createdAt: [
                        { required: true, message: '记录创建时间不能为空', trigger: 'blur' }
                    ],
                    updatedAt: [
                        { required: true, message: '记录更新时间不能为空', trigger: 'blur' }
                    ],
                }
            }
        },
        methods: {
            init (id) {
                this.dataForm.orderId = id || 0
                this.visible = true
                this.$nextTick(() => {
                    this.$refs['dataForm'].resetFields()
                    this.dataForm.orderId = id || 0
                    if (this.dataForm.orderId) {
                        this.$http({
                            url: this.$http.adornUrl(`/app/AppPredictionResults/info/\\$\\{this.dataForm.orderId}`),
                            method: 'get',
                            params: this.$http.adornParams()
                        }).then(({data}) => {
                            if (data && data.code === 0) {
                                this.dataForm = data.apppredictionresults
                            }
                        })
                    }
                })
            },
            // 表单提交
            dataFormSubmit () {
                this.$refs['dataForm'].validate((valid) => {
                    if (valid) {
                        this.$http({
                            url: this.$http.adornUrl(`/app/AppPredictionResults/\\$\\{!this.dataForm.orderId ? 'save' : 'update'}`),
                            method: 'post',
                            data: this.$http.adornData(this.dataForm)
                        }).then(({data}) => {
                            if (data && data.code === 0) {
                                this.$message({
                                    message: '操作成功',
                                    type: 'success',
                                    duration: 1500,
                                    onClose: () => {
                                        this.visible = false
                                        this.$emit('refreshDataList')
                                    }
                                })
                            } else {
                                this.$message.error(data.msg)
                            }
                        })
                    }
                })
            }
        }
    }
</script>